% Linear noise filtering - Averaging Filter
% Applied using correlation kernel
function [ fimg ] = my_nFilter( img0,img1,img2,img3,img4 )

%Images size
[w,h,c] = size(img0);

%Use a filter mask of size 5x5
kernel = ones(5,5)/25;

%Cell array to loop through each image
img = {img0, img1, img2, img3, img4};

sum = 0;
avg = 0;
fimg = zeros(5*h, w, c);

%I still dont know why the height of the image is getting bigger on the
%loop
%size(fimg)

%Walk through the image calculating the average of the neighbors and the
%new value for a given pixel
for k = 0:4
    for i = 1:h
        for j = 1:w
          avg = getAverageNeighbors(img{k+1}, i, j, 1, kernel(1,1));
          fimg(k*w+i,j,1) = avg;

          avg = getAverageNeighbors(img{k+1}, i, j, 2, kernel(1,1));
          fimg(k*w+i,j,2) = avg;

          avg = getAverageNeighbors(img{k+1}, i, j, 3, kernel(1,1));
          fimg(k*w+i,j,3) = avg;
        end
    end
end

%View results
%imshow(fimg);
%title('Exercise 3')
